from sqlalchemy import Column, String, Integer, Numeric, SmallInteger

from app.model.base import BaseModel


class Product(BaseModel):
    name = Column(String(40), nullable=False)
    price = Column(Numeric(10, 2), nullable=False)
    img = Column(String(1000), nullable=False)
    reserve = Column(Integer, nullable=False)
    valid = Column(SmallInteger, default=1)

    def tog_invalid(self):
        self.valid = 0

    def tog_valid(self):
        self.valid = 1

    def reduce(self, count):
        """
            减少库存

        :param
            count: 减少数量
        """
        self.reserve = self.reserve - count
